package com.ruoyi.chat.controller;

import com.ruoyi.chat.constant.RagFlowUrl;
import com.ruoyi.chat.domain.Chat;
import com.ruoyi.chat.service.IChaterService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天助手Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/system/chat")
public class ChaterController extends BaseController
{
    @Autowired
    private IChaterService chaterService;

    /**
     * 查询聊天助手列表
     */
    @PreAuthorize("@ss.hasPermi('system:chat:list')")
    @GetMapping("/list")
    public TableDataInfo list(Chat chat)
    {
        startPage();
        List<Chat> list = chaterService.selectChatList(chat);
        return getDataTable(list);
    }

    /**
     * 导出聊天助手列表
     */
//    @PreAuthorize("@ss.hasPermi('system:chat:export')")
//    @Log(title = "聊天助手", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Chat chat)
//    {
//        List<Chat> list = chaterService.selectChatList(chat);
//        ExcelUtil<Chat> util = new ExcelUtil<Chat>(Chat.class);
//        util.exportExcel(response, list, "聊天助手数据");
//    }

    /**
     * 获取聊天助手详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(chaterService.selectChatById(id));
    }

    /**
     * 新增聊天助手
     */
    @PreAuthorize("@ss.hasPermi('system:chat:add')")
    @Log(title = "聊天助手", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Chat chat)
    {
        return toAjax(chaterService.add(chat, RagFlowUrl.CHATS));
    }

    /**
     * 修改聊天助手
     */
    @PreAuthorize("@ss.hasPermi('system:chat:edit')")
    @Log(title = "聊天助手", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Chat chat)
    {
        return toAjax(chaterService.update(chat, RagFlowUrl.UPDATE_CHATS.replace("{chat_id}", String.valueOf(chat.getRagChatId()))));
    }

    /**
     * 删除聊天助手
     */
    @PreAuthorize("@ss.hasPermi('system:chat:remove')")
    @Log(title = "聊天助手", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chaterService.delete(ids, RagFlowUrl.DELETE_CHATS));
    }
}
